package com.leyou.item.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.enums.ExceptionEnum;
import com.leyou.common.exception.LyException;
import com.leyou.item.entity.TbSpecParam;
import com.leyou.item.mapper.TbSpecParamMapper;
import com.leyou.item.service.TbSpecParamService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 规格参数组下的参数名 服务实现类
 * </p>
 *
 * @author mybaitsplus
 * @since 2019-10-18
 */
@Service
public class TbSpecParamServiceImpl extends ServiceImpl<TbSpecParamMapper, TbSpecParam> implements TbSpecParamService {

    @Override
    @Transactional//事物
    public void addParam(TbSpecParam param) {
        if (StringUtils.isEmpty(  param.getName()))
            throw new LyException(ExceptionEnum.INVALID_PARAM_ERROR);
        boolean save = this.save(param);
        if (!save) {
            throw new LyException(ExceptionEnum.INSERT_OPERATION_FAIL);
        }
    }

    @Override
    public void deleteParamById(String id) {
        if(StringUtils.isEmpty(id))
            throw new LyException(ExceptionEnum.INVALID_PARAM_ERROR);
        boolean b = this.removeById(id);
        if (!b)
            throw new LyException(ExceptionEnum.INVALID_PARAM_ERROR);
    }

    @Override
    public void updateParam(TbSpecParam param) {
        if (StringUtils.isEmpty(param.getName()))
            throw new LyException(ExceptionEnum.INVALID_PARAM_ERROR);
        boolean save = this.updateById(param);
        if (!save) {
            throw new LyException(ExceptionEnum.INSERT_OPERATION_FAIL);
        }
    }
}
